package threadTest.runabble;

import threadTest.thread.Window;

import static java.lang.Thread.sleep;

/**
 * @author zyc
 * @create 2022--05--13 11:27
 */
public class Window1 implements Runnable {
    private static int ticket = 100;

    @Override
    public void run() {
        while (true) {
            try {
                sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (Window.class) {
                if(ticket>0){
                    System.out.println(Thread.currentThread().getName()+"当前售出第"+ticket+"张票");
                    ticket--;
                }else{
                    break;
                }
            }
        }
    }
}
